<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link href="https://cdn.bootcss.com/prism/1.15.0/plugins/line-numbers/prism-line-numbers.css" rel="stylesheet">
    <title>博客详情</title>
</head>
<body>
<!--    导航-->
<!--    inverted：反转颜色-->
<!--    attached：使圆滑弧形变方-->
    <nav th:replace="_fragments :: menu(0)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small"></nav>

<!--    中间内容-->
    <div class="m-container-small m-padded-tb-big animate__animated animate__headShake">
       <div class="ui container" style="width: 1000px">
           <div class="ui segment">
               <div class="ui top attached segment">
                   <div class="ui horizontal link list">
                       <div class="item">
                           <img th:src="@{${blog.user.avatar}}" alt="" class="ui avatar image">
                           <div class="content"><a href="#" class="header" th:text="${blog.user.nickname}"></a></div>
                       </div>
                       <div class="item">
                           <i class="calendar icon"></i>
                           <span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd')}"></span>
                       </div>
                       <div class="item">
                           <i class="eye icon"></i>
                           <span th:text="${blog.views}"></span>
                       </div>
                   </div>

               </div>
               <div class="ui attached segment">
<!--                   图片区域-->
                   <img th:src="@{${blog.firstPicture}}" alt="" class="ui rounded fluid image">
               </div>
               <div class="ui attached padded segment">
<!--                   内容-->
                   <div class="ui right aligned basic segment">
                       <div class="ui orange basic label" th:text="${blog.flag}"></div>
                   </div>
                   <h2 class="ui center aligned header" th:text="${blog.title}"></h2>
                   <br>
                   <div id="content" class="typo typo-selection js-toc-content m-padded-lr-response m-padded-tb-large" th:utext="${blog.content}">

                   </div>
                   <br>
                   <br>
                   <!--               标签-->
                   <div class="m-padded-lr"-response>
                       <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}"></div>
                   </div>
<!--                   赞赏-->
                   <div class="ui center aligned basic segment" th:if="${blog.appreciation}==1">
                       <button id="payButton" class="ui orange basic circular button">
                           赞赏
                       </button>
                   </div>

                   <div class="ui payQ flowing popup transition hidden">
                       <div class="ui orange basic label">
                           <div class="ui images" style="font-size: inherit !important;">
                               <div class="image">
                                   <img th:src="@{/images/headphoto.JPG}" alt="" class="ui rounded bordered image" style="width: 120px">
                                   <div>支付宝</div>
                               </div>
                               <div class="image">
                                   <img th:src="@{/images/headphoto.JPG}" alt="" class="ui rounded bordered image" style="width: 120px">
                                   <div>微信</div>
                               </div>
                           </div>
                       </div>
                   </div>
               </div>
               <div class="ui attached positive message">
                   <div class="ui middle aligned grid">
                       <div class="eleven wide column">
                           <ui class="list">
                               <li>作者：<span th:text="${blog.user.nickname}"></span><a th:href="@{/about}" target="_blank">(联系作者)</a></li>
                               <li>发表时间：<span th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}"></span></li>
                               <li>版权声明：自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)</li>
                               <li>公众号转载：请在文末添加作者公众号二维码</li>
                           </ui>
                       </div>
                       <div class="five wide column">
                           <img th:src="@{/images/headphoto.JPG}" alt="" class="ui right floated rounded bordered image" style="width: 120px">
                       </div>
                   </div>
               </div>
               <div class="ui bottom attached segment">
                   <div id="comment-container" class="ui teal segment">
                       <div th:fragment="commentList">
                           <div class="ui threaded comments" style="max-width: 100%">
                               <h3 class="ui dividing header">评论</h3>
                               <div class="comment" th:each="comment : ${comments}">
                                   <a class="avatar">
                                       <img th:src="@{/images/headphoto.JPG}">
                                   </a>
                                   <div class="content">
                                       <a class="author">
                                           <span th:text="${comment.nickname}"></span>
                                           <div class="ui mini basic teal left pointing label m-padded-tb-mini" th:if="${comment.adminComment}">博主</div>
                                       </a>
                                       <div class="metadata">
                                           <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}"></span>
                                       </div>
                                       <div class="text" th:text="${comment.content}"></div>
                                       <div class="actions">
                                           <a class="reply" th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}" onclick="reply(this)" >回复</a>
                                       </div>
                                   </div>
                                   <div class="comments" th:if="${#arrays.length(comment.replyComments)}">
                                       <div class="comment" th:each="reply : ${comment.replyComments}">
                                           <a class="avatar">
                                               <img th:src="@{/images/headphoto.JPG}">
                                           </a>
                                           <div class="content">
                                               <a class="author" >
                                                   <span th:text="${reply.nickname}"></span>
                                                   <div class="ui mini basic teal left pointing label m-padded-tb-mini" th:if="${reply.adminComment}">博主</div>
                                                   &nbsp;&nbsp;<span th:text="|@ ${reply.parentComment.nickname}|" class="m-teal"></span>
                                               </a>
                                               <div class="metadata">
                                                   <span class="date" th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}"></span>
                                               </div>
                                               <div class="text" th:text="${reply.content}"></div>
                                               <div class="actions">
                                                   <a class="reply" th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}" onclick="reply(this)" >回复</a>
                                               </div>
                                           </div>
                                       </div>
                                   </div>
                               </div>

                               <!--/*-->
                               <div class="comment">
                                   <a class="avatar">
                                       <img th:src="@{/images/headphoto.JPG}">
                                   </a>
                                   <div class="content">
                                       <a class="author">Elliot Fu</a>
                                       <div class="metadata">
                                           <span class="date">Yesterday at 12:30AM</span>
                                       </div>
                                       <div class="text">
                                           <p>This has been very useful for my research. Thanks as well!</p>
                                       </div>
                                       <div class="actions">
                                           <a class="reply">回復</a>
                                       </div>
                                   </div>
                                   <div class="comments">
                                       <div class="comment">
                                           <a class="avatar">
                                               <img th:src="@{/images/headphoto.JPG}">
                                           </a>
                                           <div class="content">
                                               <a class="author">Jenny Hess</a>
                                               <div class="metadata">
                                                   <span class="date">Just now</span>
                                               </div>
                                               <div class="text">
                                                   Elliot you are always so right :)
                                               </div>
                                               <div class="actions">
                                                   <a class="reply">回復</a>
                                               </div>
                                           </div>
                                       </div>
                                   </div>
                               </div>
                               <div class="comment">
                                   <a class="avatar">
                                       <img th:src="@{/images/headphoto.JPG}">
                                   </a>
                                   <div class="content">
                                       <a class="author">Joe Henderson</a>
                                       <div class="metadata">
                                           <span class="date">5 days ago</span>
                                       </div>
                                       <div class="text">
                                           Dude, this is awesome. Thanks so much
                                       </div>
                                       <div class="actions">
                                           <a class="reply">回復</a>
                                       </div>
                                   </div>
                               </div>
                               <!--*/-->
                           </div>
                       </div>

                   </div>
                   <div id="comment-form" class="ui form">
                       <input type="hidden" name="blog.id" th:value="${blog.id}">
                       <input type="hidden" name="parentComment.id" value="-1">
                       <div class="field">
                           <textarea name="content" placeholder="清输入评论信息..."></textarea>
                       </div>
                       <div class="fields">
                           <div class="field m-mobile-wide m-margin-bottom-small">
                               <div class="ui left icon input">
                                   <i class="user icon"></i>
                                   <input type="text" name="nickname" placeholder="姓名" th:value="${session.user}!=null ? ${session.user.nickname}">
                               </div>
                           </div>
                           <div class="field m-mobile-wide m-margin-bottom-small">
                               <div class="ui left icon input">
                                   <i class="mail icon"></i>
                                   <input type="text" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                               </div>
                           </div>
                           <div class="field m-mobile-wide m-margin-bottom-small">
                               <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i class="edit"></i>发布</button>
                           </div>
                       </div>
                   </div>
               </div>
           </div>
       </div>
    </div>
    </br>

    <div class="m-padded m-fixed m-right-bottom">
        <div class="ui vertical icon buttons ">
            <button type="button" class="ui toc teal button">目录</button>
            <a href="#comment-container" class="ui teal button">留言</a>
            <button class="ui wechat icon button"><i class="weixin icon"></i></button>
            <div id="toTop-button" href="#" class="ui icon button"><i class="chevron up icon"></i></div>
        </div>
    </div>

    <div class="ui toc-container flowing popup transition hidden" style="width: 250px !important;">
        <ol class="js-toc">
        </ol>
    </div>

    <div id="qrcode" class="ui wechatQR flowing popup transition hidden" style="width: 130px !important;">
    </div>

<!--    底部-->
    <footer th:replace="_fragments :: footer"></footer>

<!--/*/<th:block th:replace="_fragments :: script">/*/-->
<!--<script th:src="@{/lib/prism/prism.js}"></script>-->
<!--/*/</th:block>/*/-->
<script th:inline="javascript">


    $('.menu.toggle').click(function (){
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('#payButton').popup({
       popup : $('.payQ.popup'),
       on : 'click',
       position : 'bottom center'
    });
    tocbot.init({
        tocSelector: '.js-toc',
        contentSelector: '.js-toc-content',
        headingSelector: 'h1,h2,h3'
    });

    $('.toc.button').popup({
        popup : $('.toc-container.popup'),
        on : 'click',
        position : 'left center'
    });

    $('.wechat').popup({
        popup : $('.wechatQR'),
        position: 'left center'
    });
    //生成当前页面二维码
    var serurl=/*[[#{blog.serurl}]]*/"127.0.0.1";
    var url =/*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
        text: serurl+url,
        width: 110,
        height: 110,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });

    $('#toTop-button').click(function(){

        $(window).scrollTo(0,500);

    });

    //评论表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '請輸入評論內容~~~'
                }]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '請輸入你的大名~~~'
                }]
            },
            email:{
                identifier  :"email",
                rules:  [
                    {
                        type: 'empty',
                        prompt: "邮箱不能为空"
                    },
                    {
                        type: 'email',
                        optional: true,
                        prompt: "邮箱格式不正确"
                    }
                ]
            }
        }
    });

    $(function () {
        $('#comment-container').load(/*[[@{/comments/{id}(id=${blog.id})}]]*/);
    });

    $('#commentpost-btn').click(function(){
        var bool=$('.ui.form').form('validate form');
        if (bool){
            postData();
        }else {
            console.log("校验失败");
        }

    });

    function postData(){
        $("#comment-container").load(/*[[@{/comments}]]*/"", {
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email": $("[name='email']").val(),
            "content": $("[name='content']").val(),
        }, function (responseTxt, statusTxt, xhr) {
            //滾動條滾動事件
            // $(window).scrollTo($('#comment-container'), 500);
            clearContent();
        });
    }
    //清空內容
    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息~~~");
    }

    //點擊回復事件
    function reply(obj) {
        //data中的數據必須小寫,否則無法獲取數據的值
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');
        //設置輸入域,修改placeholder的屬性,focus:把光標定位在某個位置
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        //將commentId賦值,提交至後台
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'), 500);
    }

</script>
</body>
</html>